<html>
 <head>
  <link href="./leetcode-problem.css" rel="stylesheet" type="text/css">
 </head>
 <body>
  <div class="question_difficulty">
   难度：Easy
  </div>
  <div>
   <h1 class="question_title">
    443. String Compression
   </h1>
   <p>
    Given an array of characters, compress it
    <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">
     <b>
      in-place
     </b>
    </a>
    .
   </p>
   <p>
    The length after compression must always be smaller than or equal to the original array.
   </p>
   <p>
    Every element of the array should be a
    <b>
     character
    </b>
    (not int) of length 1.
   </p>
   <p>
    After you are done
    <b>
     modifying the input array
     <a href="https://en.wikipedia.org/wiki/In-place_algorithm" target="_blank">
      in-place
     </a>
    </b>
    , return the new length of the array.
   </p>
   &nbsp;
   <p>
    <b>
     Follow up:
    </b>
    <br>
    Could you solve it using only O(1) extra space?
   </p>
   &nbsp;
   <p>
    <b>
     Example 1:
    </b>
   </p>
   <pre>
<b>Input:</b>
["a","a","b","b","c","c","c"]

<b>Output:</b>
Return 6, and the first 6 characters of the input array should be: ["a","2","b","2","c","3"]

<b>Explanation:</b>
"aa" is replaced by "a2". "bb" is replaced by "b2". "ccc" is replaced by "c3".
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <b>
     Example 2:
    </b>
   </p>
   <pre>
<b>Input:</b>
["a"]

<b>Output:</b>
Return 1, and the first 1 characters of the input array should be: ["a"]

<b>Explanation:</b>
Nothing is replaced.
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <b>
     Example 3:
    </b>
   </p>
   <pre>
<b>Input:</b>
["a","b","b","b","b","b","b","b","b","b","b","b","b"]

<b>Output:</b>
Return 4, and the first 4 characters of the input array should be: ["a","b","1","2"].

<b>Explanation:</b>
Since the character "a" does not repeat, it is not compressed. "bbbbbbbbbbbb" is replaced by "b12".
Notice each digit has it's own entry in the array.
</pre>
   <p>
    &nbsp;
   </p>
   <p>
    <b>
     Note:
    </b>
   </p>
   <ol>
    <li>
     All characters have an ASCII value in
     <code>
      [35, 126]
     </code>
     .
    </li>
    <li>
     <code>
      1 &lt;= len(chars) &lt;= 1000
     </code>
     .
    </li>
   </ol>
  </div>
  <div>
   <h1 class="question_title">
    443. 压缩字符串
   </h1>
   <p>
    给定一组字符，使用
    <a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95">
     原地算法
    </a>
    将其压缩。
   </p>
   <p>
    压缩后的长度必须始终小于或等于原数组长度。
   </p>
   <p>
    数组的每个元素应该是长度为1&nbsp;的
    <strong>
     字符
    </strong>
    （不是 int 整数类型）。
   </p>
   <p>
    在完成
    <a href="https://baike.baidu.com/item/%E5%8E%9F%E5%9C%B0%E7%AE%97%E6%B3%95">
     原地
    </a>
    <strong>
     修改输入数组
    </strong>
    后，返回数组的新长度。
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     进阶：
    </strong>
    <br>
    你能否仅使用O(1) 空间解决问题？
   </p>
   <p>
    &nbsp;
   </p>
   <p>
    <strong>
     示例 1：
    </strong>
   </p>
   <pre>
<strong>输入：</strong>
["a","a","b","b","c","c","c"]

<strong>输出：</strong>
返回6，输入数组的前6个字符应该是：["a","2","b","2","c","3"]

<strong>说明：</strong>
"aa"被"a2"替代。"bb"被"b2"替代。"ccc"被"c3"替代。
</pre>
   <p>
    <strong>
     示例 2：
    </strong>
   </p>
   <pre>
<strong>输入：</strong>
["a"]

<strong>输出：</strong>
返回1，输入数组的前1个字符应该是：["a"]

<strong>说明：</strong>
没有任何字符串被替代。
</pre>
   <p>
    <strong>
     示例 3：
    </strong>
   </p>
   <pre>
<strong>输入：</strong>
["a","b","b","b","b","b","b","b","b","b","b","b","b"]

<strong>输出：</strong>
返回4，输入数组的前4个字符应该是：["a","b","1","2"]。

<strong>说明：</strong>
由于字符"a"不重复，所以不会被压缩。"bbbbbbbbbbbb"被&ldquo;b12&rdquo;替代。
注意每个数字在数组中都有它自己的位置。
</pre>
   <p>
    <strong>
     注意：
    </strong>
   </p>
   <ol>
    <li>
     所有字符都有一个ASCII值在
     <code>
      [35, 126]
     </code>
     区间内。
    </li>
    <li>
     <code>
      1 &lt;= len(chars) &lt;= 1000
     </code>
     。
    </li>
   </ol>
  </div>
 </body>
</html>